package top.tagao.features_05_time;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.concurrent.*;

/**
 * @author fu-xiao-liu
 * @Date 2022/3/20 21:31
 * 传统的日期格式存在的线程不安全问题
 * (通过加锁解决线程问题)
 */
public class Time_02_Problem {

    public static void main(String[] args) throws ExecutionException, InterruptedException {

        Callable<Date> task = ()-> DateFormatThreadLocal.convert("20161218");

        ExecutorService pool = Executors.newFixedThreadPool(10);
        ArrayList<Future<Date>> results = new ArrayList<>();

        for (int i = 0; i < 10; i++) {
            results.add(pool.submit(task));
        }

        for (Future<Date> future : results){
            System.out.println(future.get());
        }
        pool.shutdown();
    }


}
